﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ServiceStack.ServiceInterface.ServiceModel;
using MMM.Core;

namespace MMM.Services.Response
{
    [Serializable]
    public class OperationResult<T> : IHasResponseStatus
    {
        /// <summary>
        /// 失败
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static OperationResult<T> FailureResponse(string msg)
        {

            falsRes.ResponseStatus.Message = msg;

            return falsRes;
        }

        static OperationResult<T> falsRes = new OperationResult<T>() { success = false };

        static OperationResult<T> succRes = new OperationResult<T>() { success = true };
        /// <summary>
        /// 成功后无返回值
        /// </summary>
        public static OperationResult<T> SuccessRespose = new OperationResult<T>() { ResponseStatus = new ResponseStatus(), success = true };

        /// <summary>
        /// 成功后有返回值
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static OperationResult<T> SuccessRespose1(string msg)
        {

            succRes.ResponseStatus.Message = msg;

            return succRes;
        }


        public OperationResult()
            : this(new List<T>(), 0)
        {
            success = true;
        }

        public OperationResult(IList<T> list, int totalcount)
        {
            this.Data = list;
            this.TotalCount = totalcount;
            success = true;
            this.ResponseStatus = new ResponseStatus();
        }

        public OperationResult(PageResult<T> pageresult)
            : this(pageresult.Result, pageresult.TotalCount)
        {
        }

        public bool success { get; set; }

        public IList<T> Data { get; private set; }

        public int TotalCount { get; private set; }

        public ResponseStatus ResponseStatus
        {
            get;
            set;
        }
    }
}
